package com.gxa.service.discrepancy.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gxa.entity.discrepancy.AccessControl;
import com.gxa.entity.discrepancy.search.AccessControlSearchMap;
import com.gxa.mapper.discrepancy.AccessControlMapper;
import com.gxa.service.discrepancy.AccessControlService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Set;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author yjl
 * @since 2022-10-12 11:43:53
 */
@Service
public class AccessControlServiceImpl extends ServiceImpl<AccessControlMapper, AccessControl> implements AccessControlService {
    @Autowired
    private AccessControlMapper mapper;
    @Override
    public PageInfo<AccessControl> queryByPage(AccessControlSearchMap map) {
        PageHelper.startPage(map.getPageNum(),map.getPageSize());//1.开启分页

        QueryWrapper<AccessControl> wrapper = new QueryWrapper<>();//2.条件构造器 模拟写动态sql  或者在xml 中写
        if (!StringUtils.isAnyBlank(map.getName())) {
            wrapper.like("apply_person", map.getName());
        }
        if (!StringUtils.isAnyBlank(map.getPhone())) {
            wrapper.like("phone", map.getPhone());
        }
        if (!StringUtils.isAnyBlank(map.getIdCard())) {
            wrapper.like("id_card", map.getIdCard());
        }
        if (!StringUtils.isAnyBlank(map.getHomeLocation())) {
            wrapper.like("home", map.getHomeLocation());
        }
        if (map.getStatus() != null) {
            wrapper.eq("apply_status", map.getStatus());
        }

        if(!StringUtils.isAnyBlank(map.getStartTime(),map.getEndTime())){
            wrapper.between("apply_time",map.getStartTime(),map.getEndTime());
        }
        PageInfo<AccessControl> pageInfo = new PageInfo<>(mapper.selectList(wrapper));//3.获取分页信息
        return pageInfo;
    }

    @Override
    public Set<String> homeLocations() {
        return mapper.homeLocations();
    }


}
